<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Traits;

use App\AppRequest;
use App\AppResponse;
use App\Constants\RespCode;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;

/**
 * Trait ResponseTrait.
 */
trait ResponseTrait
{
    #[Inject]
    protected AppResponse $response;

    #[Inject]
    protected AppRequest $request;

    public function success(array|object $data = [], string $message = '操作成功', int $code = RespCode::SUCCESS): ResponseInterface
    {
        return $this->response->success($message, $data, $code);
    }

    public function error(string $message = '操作失败', int $code = RespCode::ERROR, array|object $data = []): ResponseInterface
    {
        return $this->response->error($message, $code, $data);
    }
}
